import threading
from time import sleep, ctime
loops = (4, 2)
class MyThread(threading.Thread):
    def __init__(self,*args):
        threading.Thread.__init__(self)
        self.args = args

    def run(self):
        #print 'start loop', self.args[0], 'at:', ctime()
        sleep(self.args[1])
        #print 'loop', self.args[0], 'done at:', ctime()

def main():
    print 'starting at:', ctime()
    threads = []
    nloops = range(len(loops))
    
    for i in nloops:
        t = MyThread(*(i, loops[i]))
        threads.append(t)
    
    for i in nloops:
        threads[i].start()

    for i in nloops:
        print '---------------------'
        threads[i].join()

    print 'all DONE at:', ctime()
        
if __name__ == '__main__':
    main()
    print 'end'
